package us.gaaoc.framework.webapp.backingbeans.admin;

import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import us.gaaoc.framework.dao.ModelFacade;
import us.gaaoc.framework.dao.ModelFacadeHibernate;
import us.gaaoc.framework.model.CaseRecordHistory;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * 
 * @author tapshals
 * @date May 25, 2006
 * @version: GAJE 1.5
 * 
 */
public class CaseRecordHistoryPage extends BaseBackingBean {

	/**
	 * properties
	 */
	private DataModel historyDataTable;

	/**
	 * Costructor
	 *
	 */
	public CaseRecordHistoryPage() {
		this.loadData();
	}

	/**
	 * This method loads the data from the 
	 * database for the particular caseRecord.
	 *
	 */
	private void loadData() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String caseUuid = (String) sessionMap.get("caseUuid");
		String courtUuid = (String) sessionMap.get("courtUuid");
		List<CaseRecordHistory> historyList = this.getModelFacade()
				.findHistoryByCaseRecordID(caseUuid, courtUuid);
		historyDataTable = new ListDataModel();
		historyDataTable.setWrappedData(historyList);
	}

	/**
	 * Getter for property historyDataTable
	 * @return historyDataTable
	 */
	public DataModel getHistoryDataTable() {
		return historyDataTable;
	}

	/**
	 * Setter for property historyDataTable
	 * @param historyDataTable
	 */
	public void setHistoryDataTable(DataModel historyDataTable) {
		this.historyDataTable = historyDataTable;
	}

	/**
	 * This method navigates user to the previous page.
	 * @return
	 */
	public String back() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String fromPage = (String) sessionMap.get("from");
		sessionMap.remove("from");
		sessionMap.remove("caseUuid");

		if (fromPage.equalsIgnoreCase("ChildEnforcementCaseTypePage")) {
			return "gotoChildEnforcementCaseTypePage";
		} else if (fromPage.equalsIgnoreCase("ReceivedFilingPage")) {
			return "received";
		} else if (fromPage.equalsIgnoreCase("RejectedFilingPage")) {
			return "rejected";
		} else if (fromPage.equalsIgnoreCase("ImportedFilingPage")) {
			return "imported";
		} else if (fromPage.equalsIgnoreCase("DisposedFilingPage")) {
			return "disposed";
		} else if (fromPage.equalsIgnoreCase("ServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("NonServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("TransmissionErrorFilingPage")) {
			return "transmissionErrorFilingPage";
		}else if (fromPage.equalsIgnoreCase("searchPage")){
			sessionMap.put("from", "adminChildEnforcementCaseTypePage");
			return "searchPage";
		}else
			return "";
	}
}
